Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

workbox-expiration

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

workbox-expiration

A service worker helper library that expires cached responses based on age or maximum number of entries.

  • 4.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3M
decreased by-29.07%
Maintainers
2
Weekly downloads
 
Created

What is workbox-expiration?

The workbox-expiration package is part of the Workbox suite of libraries, which are designed to make it easier to build offline-first, service worker-powered web applications. The workbox-expiration plugin specifically manages the cache expiration and limits the number of entries in a cache.

What are workbox-expiration's main functionalities?

Cache Expiration

This feature allows you to set expiration parameters for cached responses. In the code sample, a cache-first strategy is used for requests to 'https://example.com', with a maximum of 60 entries and a maximum age of 30 days before the cached entries are purged.

workbox.routing.registerRoute(
  ({url}) => url.origin === 'https://example.com',
  new workbox.strategies.CacheFirst({
    cacheName: 'images',
    plugins: [
      new workbox.expiration.ExpirationPlugin({
        maxEntries: 60,
        maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
      }),
    ],
  }),
);

Cache Entry Limit

This feature limits the number of entries in a cache. In the code sample, a stale-while-revalidate strategy is used for requests to 'https://example.com', with a maximum of 50 entries in the 'articles' cache.

workbox.routing.registerRoute(
  ({url}) => url.origin === 'https://example.com',
  new workbox.strategies.StaleWhileRevalidate({
    cacheName: 'articles',
    plugins: [
      new workbox.expiration.ExpirationPlugin({
        maxEntries: 50,
      }),
    ],
  }),
);

Purge on Quota Error

This feature automatically purges caches if the browser's storage quota is exceeded. In the code sample, a network-first strategy is used for requests to 'https://example.com', with the 'purgeOnQuotaError' option set to true.

workbox.routing.registerRoute(
  ({url}) => url.origin === 'https://example.com',
  new workbox.strategies.NetworkFirst({
    cacheName: 'documents',
    plugins: [
      new workbox.expiration.ExpirationPlugin({
        purgeOnQuotaError: true, // Automatically delete caches if quota is exceeded
      }),
    ],
  }),
);

Other packages similar to workbox-expiration

Keywords

FAQs

Package last updated on 01 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc